﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AzureProvider.MiniSensor;
using AzureProvider.ssdsClient;

namespace AzureProvider.SoupMethods.MiniSensor
{
    public class ChannelMethods:BaseMethods 
    {
        protected override string containerId
        {
            get { return "MiniSensor"; }
        }

        protected override string kind
        {
            get { return "Channel"; }
        }

        protected override AzureProvider.ssdsClient.Entity CreateEntity(object Object)
        {
            Channel channel = (Channel)Object;

            var entity = new Entity()
            {
                Id = channel.Id.ToString(),
                Kind = kind
            };

            entity.Properties = new Dictionary<string, object>();
            entity.Properties.Add("Author",channel.Author);
            entity.Properties.Add("Name", channel.Name);
            
            return entity;
        }

        public override object CreateObject(AzureProvider.ssdsClient.Entity Entity)
        {
            Channel channel = new Channel
            {
                Id = new Guid(Entity.Id),
                Name =(string)Entity.Properties["Name"],
                Author=(string)Entity.Properties["Author"]
            };
            
            return channel;
        }

        public IEnumerable<Channel> GetChannels(string query, out string errMessage)
        {
            return base.GetObjects(query, out errMessage).Cast<Channel>();
        }
        public void FillMessages(ref Channel channel, out string errMessage)
        {
            MessageMethods MessMethods = new MessageMethods();
            channel.Messages.AddRange(MessMethods.GetMessages(channel.Id.ToString(),out errMessage).ToArray());
        }
    }
}
